package com.pacyki.database;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;

public class BackgroundCategories {
	
	private DbAdapter mDbAdapter;
	private Cursor mCategoriesCursor;
	private Context mContext;
	
	BackgroundCategories(Context ctx) {
		mContext = ctx;
		mDbAdapter = new DbAdapter(mContext);
		mCategoriesCursor = mDbAdapter.getBGCategories();
	}
	
	public int getCount() {
		return mCategoriesCursor.getCount();		
	}
	
	public BackgroundCategory getCategoryByIndex(int index) {
		return new BackgroundCategory(index);
	}
	
	public void finalize() {
		mCategoriesCursor.close();
	}
	
	private class BackgroundCategory {
		
		private Cursor mCategoryCursor;
		private String TABLE_COLUMN_ID = "bgcid";
		private String TABLE_COLUMN_NAME = "name";
		
		BackgroundCategory(int index) {
			mCategoriesCursor.moveToPosition(index);
			int id = mCategoriesCursor.getInt(0);
			mCategoryCursor = mDbAdapter.getBGCategory(id);
		}
		
		public String getName() {
			int nameColumn = mCategoryCursor.getColumnIndex(TABLE_COLUMN_NAME);
			return mCategoryCursor.getString(nameColumn);
		}
		
		public int getId() {
			int idColumn = mCategoryCursor.getColumnIndex(TABLE_COLUMN_ID);
			return mCategoryCursor.getInt(idColumn);
		}
		
		public void finalize() {
			mCategoryCursor.close();
		}
		
	}
}
